<?php

require_once("config.php");
require_once("lib/logging.php");
require_once("classes/mysql.php");
require_once("classes/template.php");
require_once("classes/session.php");
require_once("lib/common.php");
require_once("lib/data.php");
require_once("lib/data2.php");
require_once("lib/zones.php");

$editor = (isset($_GET['editor']) ? $_GET['editor'] : '');
$action = (isset($_GET['action']) ? $_GET['action'] : 0);
$npcid = (isset($_GET['npcid']) ? $_GET['npcid'] : null);
$exp = (isset($_GET['exp']) ? $_GET['exp'] : '');
$z = (isset($_GET['z']) ? $_GET['z'] : '');
$searchbar = '';
$body = '';
$login_area='';
$menu_area='';
$javascript = '';
$breadcrumbs = '';
$questNPCs = getTotalQuestNPCs();
$quests = getTotalDatabaseQuests();
$login = $_SESSION['login'];

//require_once('lib/headbars.php');
//require_once('lib/breadcrumbs.php');

if (isset($_GET['admin'])) {
  if (session::is_admin()) {
    require_once('lib/admin.php');
  }
}

switch ($editor) {
  case '':
    $menu_area=new Template("templates/menu/menu.default.tmpl.php");
    $body = new Template("templates/intro.tmpl.php");
    break;
  case 'exp':
    require_once('lib/exp.php');
    break;
  case 'epics':
    require_once('lib/epics.php');
    break;
  case 'npc':
    require_once('lib/npc.php');
    break;
  case 'team':
    require_once('lib/team.php');
    break;
}

$tmpl->set('quests', $quests);
$tmpl->set('questNPCs', $questNPCs);

if (session::logged_in() == TRUE) {
// $login = $_SESSION['login'];
  $admin = '';
  $loggedInGuest='';
  if (session::is_admin()) {
    $admin = "<a href=\"index.php?admin\">Admin</a> |";
    }
  if (isset($_SESSION['guest']) && $_SESSION['guest'] == 1) {
    $loggedInGuest='Guest';
    }
  $login_area = new Template("templates/login/loggedin.tmpl.php");

  $login_area->set('login', $login);
  $login_area->set('loggedInGuest', $loggedInGuest);
  $login_area->set('admin', $admin);

$tmpl->set('javascript', $javascript);
$tmpl->set('headbar', $headbar);
$tmpl->set('searchbar', $searchbar);
$tmpl->set('breadcrumbs', $breadcrumbs);
$tmpl->set('menu_area', $menu_area);
$tmpl->set('body', $body);
$tmpl->set('login_area', $login_area);
$body->set('login', $login);
    


echo $tmpl->fetch('templates/index.tmpl.php');
exit;
}

function getTotalDatabaseQuests() {
  global $mysql;
  
  $query= "select count(quest_id) from qed_quests";
  $result = $mysql->mysql_one_data($query);
  return $result;
}
function getTotalQuestNPCs() {
  global $mysql;
  
  $query= "select count(distinct questgiver_npcid) from qed_quests";
  $result = $mysql->mysql_one_data($query);
  return $result;
}
?>
